import time

from selenium import webdriver
from selenium.webdriver.remote.webdriver import WebDriver

from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

TIMEOIUT=10
class Page:

    def __init__(self,driver:WebDriver):
        self.driver =driver
    #打开浏览器
    def goto(self,url):
        self.driver.get(url)
    #关闭浏览器
    def quit(self):
        time.sleep(5)
        self.driver.quit()

    def wait_time(self,loc,timeout=None)->WebElement:
        timeout = TIMEOIUT if timeout is None else timeout
        wait = WebDriverWait(self.driver, timeout=timeout)
        return wait.until(expected_conditions.element_to_be_clickable(loc))

    #点击
    def click(self,loc):
        self.wait_time(loc)
    #输入
    def send_keys(self,loc,value):
        self.wait_time(loc).send_keys(value)



